/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbclasses;

import classes.Invoice;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 * Class for dealing with invoice objects in the database.
 * @author keaneb1
 */
public class InvoiceDB {
    private static Connection conn = null;
    private static PreparedStatement prest = null;
    
    
    public static boolean insertNewInvoice(Invoice newInvoice) {
        
        //create the SQL statement for inserting a new booking into the database
        String query = "INSERT INTO invoice (booking_no,total_paid) VALUES (?,?)";
        boolean success = false;
        /*
         * Create a new connection, execute the insert statement putting the booking into the database.
         */
       
        conn = Dbconnector.getConnected();
        if(conn!=null){
            try {
                //execute the insert statement filling each column in the table
                prest = conn.prepareStatement(query);
                prest.setInt(1, newInvoice.getNewBooking().getId());
                prest.setDouble(2, newInvoice.getTotal_paid());
                prest.executeUpdate();
                conn.close();
                success = true;
            
            } catch (SQLException ex) {
                //tell the client which method call errored out and what was the message
                JOptionPane.showMessageDialog(null, "Problem in insertNewInvoice " +ex.getMessage());
            }
        }
        return success;
    }
}
